package api

import (
	"github.com/gin-gonic/gin"
	"go.uber.org/zap"
	"seat-service/initialization"
	"seat-service/model/dto"
	"seat-service/response"
	service "seat-service/service/impl"
)

var qrCodeService service.QrCodeService

type QrCodeApi struct {
}

func (q *QrCodeApi) WriteCode(context *gin.Context) {
	//接收请求参数
	var codeInformation []dto.WriteCodeParam
	//body, _ := ioutil.ReadAll(context.Request.Body)
	//fmt.Println(string(body))
	if err := context.ShouldBindJSON(&codeInformation); err != nil {
		initialization.SeatLogger.Error("context.ShouldBindJSON(&codeInformation) is failed", zap.Error(err))
		resp.Fail(context, response.CodeParamError, nil)
		return
	}
	if err := qrCodeService.WriteQRCode(codeInformation); err != nil {
		initialization.SeatLogger.Error("qrCodeService.WriteQRCode(codeInformation is failed", zap.Error(err))
		resp.Fail(context, response.CodeServerBusy, nil)
		return
	}
	resp.Success(context, response.CodeSuccess, nil)
}
